package streamtest;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Test03 {
    public static void main(String[] args) {
        //定义两个集合分别存储男演员和女演员，姓名和年龄,比如：张三，23
        ArrayList<String> manList = new ArrayList<>();
        ArrayList<String> womanList = new ArrayList<>();
        Collections.addAll(manList,"张三三-23","李四四-24","王五五-25","赵六-26");
        Collections.addAll(womanList,"范冰冰-23","刘亦菲-25","刘美美-26","刘小宝-27");

        //男演员只要名字为3个字的前两人
        Stream<String> s1 = manList.stream().filter(s -> s.split("-")[0].length() == 3)
                .limit(2);
        //女演员只要姓刘的不要第一个
        Stream<String> s2 = womanList.stream().filter(s -> s.split("-")[0].startsWith("刘"))
                .skip(1);

        //把过滤后的合并
        //把演员的信息封装成Actor对象
        //s.split("-")[0]就是 姓名
        //Integer.parseInt(s.split("-")[1]) 就是年龄
        //然后存入new出来的Actor对象
        //然后把Actor对象放入List集合中
        List<Actor> collect = Stream.concat(s1, s2)
                .map(s -> new Actor(s.split("-")[0], Integer.parseInt(s.split("-")[1])))
                .collect(Collectors.toList());
        System.out.println(collect);
    }
}
class Actor{
    private String name;
    private int age;

    public Actor(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Actor{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
